#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define P(i) p[i-1]
#define M(i,j) m[(i-1)*n+j-1]
#define S(i,j) s[(i-1)*n+j-1]
int printopt(int *s,int n,int i,int j)
{
	if(i==j)
	{
		printf("A%d",i);
	}
	else
	{
		printf("(");
		printopt(s,n,i,S(i,j));
		printopt(s,n,S(i,j)+1,j);
		printf(")");
	}
}
int main()
{
	int i,j,k,l;
	int n,temp;
	unsigned int *p;
	unsigned int *m;
	int *s;
	scanf("%d",&n);
	p=(unsigned int *)malloc((n+1)*sizeof(int));
	m=(unsigned int *)malloc(n*n*sizeof(int));
	s=(int *)malloc(n*n*sizeof(int));
	for(i=1;i<=n+1;i++) scanf("%u",&P(i));
	for(i=1;i<=n;i++) M(i,i)=0;
	for(l=2;l<=n;l++)
	{
		for(i=1;i<=(n-l+1);i++)
		{
			j=i+l-1;
			M(i,j)=1000000;
			for(k=i;k<=j-1;k++)
			{
				temp=P(i)*P(k+1)*P(j+1)+M(i,k)+M(k+1,j);
				if(temp<M(i,j)) M(i,j)=temp,S(i,j)=k;
			}
		}
	}
	printf("%u %u\n",M(1,n),S(1,n));

	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			printf(" %d ",M(i,j));
		}
		printf("\n");
	}
	
	for(i=1;i<=n;i++)
	{
		for(j=i;j<=n;j++)
		{
			printf(" %d ",S(i,j));
		}
		printf("\n");
	}
	printopt(s,n,1,n);
	free(p);
	free(m);
	free(s);
	return 0;
}


